package com.ys.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 新增数据返回后续操作
 * @author Jason
 *
 */
@Data
@AllArgsConstructor
public class AddDto {
	private Integer code;
	private Long id;
	private String url;
	
    public enum Code {
    	
    	NO_ACTION("无动作", 0), GOTO_EDIT("跳转编辑页", 1), CLODE_AND_RELOAD("关闭当前页并刷新父列表", 2);
    	public String name;
    	public Integer value;

    	private Code(String name, Integer value) {
    		this.name = name;
    		this.value = value;
    	}

    	public static String getName(int value) {
    		for (Code e : Code.values()) {
    			if (e.value == value) {
    				return e.name;
    			}
    		}

    		return "";
    	}
    }
    
    public static AddDto noAction() {
    	return new AddDto(Code.NO_ACTION.value, null, null);
    }
    
    public static AddDto gotoEdit(String url) {
    	return new AddDto(Code.GOTO_EDIT.value, null, url);
    }
    
    public static AddDto closeAndReload() {
    	return new AddDto(Code.CLODE_AND_RELOAD.value, null, null);
    }
}